package com.dayu.recovery.service.impl;

import java.util.List;

import com.dayu.common.utils.DateUtils;
import com.dayu.common.utils.SecurityUtils;
import org.springframework.stereotype.Service;
import com.dayu.recovery.mapper.RecoveryBlacklistMapper;
import com.dayu.recovery.domain.RecoveryBlacklist;
import com.dayu.recovery.service.IRecoveryBlacklistService;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;

/**
 * 商品黑名单Service业务层处理
 * 
 * @author HK
 * @date 2024-01-06
 */
@Service
public class RecoveryBlacklistServiceImpl implements IRecoveryBlacklistService 
{
    @Resource
    private RecoveryBlacklistMapper recoveryBlacklistMapper;

    /**
     * 查询商品黑名单列表
     * 
     * @param recoveryBlacklist 商品黑名单
     * @return 商品黑名单
     */
    @Override
    public List<RecoveryBlacklist> selectRecoveryBlacklistList(RecoveryBlacklist recoveryBlacklist)
    {
        return recoveryBlacklistMapper.selectRecoveryBlacklistList(recoveryBlacklist);
    }

    /**
     * 新增商品黑名单
     * 
     * @param bo 商品黑名单
     * @return 结果
     */
    @Override
    public int insertRecoveryBlacklist(RecoveryBlacklist bo)
    {

        if(ObjectUtils.isEmpty(bo.getGoodsId()))
            throw new RuntimeException("goodsId不能为空");
        if(ObjectUtils.isEmpty(bo.getImei()))
            throw new RuntimeException("IMEI不能为空");
        RecoveryBlacklist blacklist = recoveryBlacklistMapper.queryBlackByGoodsIdAndIMEI(bo.getGoodsId(), bo.getImei());

        if(!ObjectUtils.isEmpty(blacklist))
            throw new RuntimeException("请勿重复添加");

        bo.setCreateTime(DateUtils.getNowDate());
        bo.setCreateName(SecurityUtils.getLoginUser().getUser().getNickName());
        bo.setCreateBy(SecurityUtils.getUsername());
        return recoveryBlacklistMapper.insertRecoveryBlacklist(bo);
    }

    /**
     * 批量删除商品黑名单
     * 
     * @param ids 需要删除的商品黑名单ID
     * @return 结果
     */
    @Override
    public int deleteRecoveryBlacklistByIds(Long[] ids)
    {
        return recoveryBlacklistMapper.deleteRecoveryBlacklistByIds(ids);
    }
}
